<!-- mod by luoji  all file -->
<template>
  <a-modal
    v-model="visible"
    :title="'导入导出'"
    :maskClosable="false"
    :keyboard="false"
    :confirmLoading="confirmLoading"
    :destroyOnClose="true"
    :width="700"
    @ok="ok"
    @cancel="close"
  > 
    <div class="popWindow" v-if="isRouterAlive||true">
      <a-row>
        <a-col :span="24">
          <a-upload
            name="file"
            :multiple="false"
            action="/api/api/ExcelPOIController/upload"
          >
          <a-button> <a-icon type="upload" /> 导入 </a-button>
        </a-upload>
        </a-col>
      </a-row>
    </div>
    <template slot="footer">
      <a-button key="cancel" @click="close">关闭</a-button>
    </template>
  </a-modal>
</template>

<script lang="ts">

import {
  Component, Vue, Prop, Watch
} from 'vue-property-decorator';
import Axios from 'axios'
import {
  Modal,
  Row,
  Col,
  Input,
  Alert,
  Button
} from '@h3/antd-vue';

import { homeApi,userApi } from "@cloudpivot/api";

@Component({
  name: 'form-modify-import-export',
  components: {
    AModal: Modal,
    ARow: Row,
    ACol: Col,
    Alert,
    ATextarea: Input.TextArea,
  }
})
export default class ImportExportModal extends Vue {
  
  visible: boolean = false;
  file: any;

  confirmLoading: boolean = false;
  action: any = "";
  isRouterAlive: boolean = true;
  layout: any = {
    left: 6,
    right: 18
  }

  exportData(){
    alert('导出')
  }

  exportTmp(){
    alert('导出模板')
  }
  
  importData(){
    alert('导入')
    console.log(this.$refs.file);
    
  }

  async init(num: number, action: any) {
    this.action = action;
    this.show();
  }
  show() {
    this.visible = true;
  }

  close() {
    this.confirmLoading = false;
    this.visible = false;
  }

  ok() {
    var idsStr=sessionStorage.getItem("sessionKey");
    var sessionCode= sessionStorage.getItem("sessionCode");
    let arr: any = null;
    if(idsStr){
        arr = idsStr.split(',');
    }
    var suppliers:any=[];
    var newparams :any =new Object();
    newparams.id=this.user[0].id; //供应商id
    suppliers.push(newparams);
    var ajaxurl="";
    switch(sessionCode)
    {
      case "CYCLWPXQC":
        ajaxurl="/api/materials/addMaterials";
        break;
      case "BPCG":
        ajaxurl="/api/invitation/addMaterials";
        break;
      case "DZBGXQC":
        ajaxurl="/api/bigAnt/addMaterials";
        break;
    }

    Axios.post(ajaxurl,{
      ids: arr,
      suppliers: suppliers,
      }).then((res:any)=>{
        debugger;
        if(res.errmsg!="SUCCESS"){
          alert("订单信息生成失败");
        }else{
          this.close();
        }
      });

    console.log(sessionStorage.getItem("sessionKey"));
  }

  reload(){
      this.isRouterAlive=false;
      this.$nextTick(function(){
        this.isRouterAlive=true
      })
    }
}
</script>

<style lang="less" scoped>
    .popWindow .ant-col{
      padding: 2px !important;
    }

    .popWindow .popHeader{
      margin-top: 10px;
      padding: 5px 8px;
      border-top: 1px solid #DDD;
    }

    .popWindow .popWindow_row{
      border-bottom: 1px solid #DDD;
    }
</style>
